<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use App\Http\Models\CacheModel;

class MusicModel extends Model
{
    const CACHE_KEY = 'music:';

	protected $connection = 'db_main_slave';

	protected $table = 'wp_sdk_material_music';

    public static function getDefaultList()
    {
        if($list = CacheModel::get(self::CACHE_KEY . 'all')) {
            return json_decode($list, true);
        } else {
            $list = self::where(["is_default" => 1, "status" => 1])->get();
            if($list) {
                $time = time();
                $expire = strtotime(date('Y-m-d', $time + 86400)) + 1800 - $time; //第二天上午五点失效
                CacheModel::set(self::CACHE_KEY . 'all',  json_encode($list), $expire);
            }
            return $list;
        }
    }

    public static function info( $id )
    {
        return self::where(["id" => $id, "status"=> 1]) ->first();
    }
}

